package com.ezjie.ielts.module_word.adapter;

import java.util.List;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ezjie.ielts.R;
import com.ezjie.ielts.model.CadicatesBean;
import com.ezjie.ielts.model.Mean;
import com.ezjie.ielts.util.ListUtils;

public class WordGroupAdapter extends BaseAdapter {
	private Context mContext;
	private List<CadicatesBean> list;
	private LayoutInflater mInflater;

	public WordGroupAdapter(Context context) {
		this.mContext = context;
		this.mInflater = LayoutInflater.from(context);
	}

	public void setList(List<CadicatesBean> list) {
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (null == convertView) {

			convertView = LayoutInflater.from(mContext).inflate(R.layout.layout_word_group_listview_item, null);
			holder = new ViewHolder();
			holder.ll_content = (LinearLayout) convertView.findViewById(R.id.ll_content);
			holder.tv_word = (TextView) convertView.findViewById(R.id.tv_word);
			holder.tv_phonetic = (TextView) convertView.findViewById(R.id.tv_phonetic);
			holder.tv_transfer = (TextView) convertView.findViewById(R.id.tv_transfer);
			holder.tv_head = (TextView) convertView.findViewById(R.id.tv_head);

			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		CadicatesBean cadicatesBean = list.get(position);
		if (cadicatesBean != null) {

			holder.ll_content.setVisibility(View.VISIBLE);
			holder.tv_word.setText(Html.fromHtml(cadicatesBean.getWord()));
			holder.tv_phonetic.setText(Html.fromHtml(cadicatesBean.getPhonetic()));
			List<Mean> means = cadicatesBean.getMeans();
			holder.tv_transfer.setText(Html.fromHtml(ListUtils.getTransferStr1ByList(means)));

		}

		return convertView;
	}

	class ViewHolder {
		LinearLayout ll_content;

		TextView tv_word;
		TextView tv_phonetic;
		TextView tv_transfer;
		TextView tv_head;

	}

}
